﻿Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Partial Class UserControls_DateSelector
    Inherits System.Web.UI.UserControl

    ' This propery sets/gets the calendar date
    Public Property CalendarDate() As String
        Get
            Return txt_Date.Text
        End Get
        Set(ByVal value As String)
            txt_Date.Text = value
        End Set
    End Property

    ' This Property sets or gets the the label for 
    ' Dateselector user control
    Public Property Text() As String
        Get
            Return lblDate.Text
        End Get
        Set(ByVal value As String)
            lblDate.Text = value
        End Set
    End Property

    Public WriteOnly Property Enable() As Boolean
        Set(ByVal value As Boolean)
            Dim scriptStr As String = "javascript:return popUpCalendar(this," & getClientID() & ", 'dd/mm/yyyy', '__doPostBack(\'" & getClientID() & "\')')"
            tbl_control.Disabled = Not value
            txt_Date.Enabled = value
            If tbl_control.Disabled = False Then
                imgCalendar.Attributes.Add("onclick", scriptStr)
            Else
                imgCalendar.Attributes.Clear()
            End If
        End Set
    End Property

    Public Property CauseValidation() As Boolean
        Get
            Return validateDate.Visible
        End Get
        Set(ByVal value As Boolean)
            validateDate.Visible = value
        End Set
    End Property

    Public ReadOnly Property DateTextBox() As TextBox
        Get
            Return txt_Date
        End Get
    End Property


    ' Get the id of the control rendered on client side
    ' Very essential for Javascript Calendar scripts to locate the textbox
    Public Function getClientID() As String
        Return txt_Date.ClientID
    End Function

#Region "Web Form Designer generated code"
    Protected Overrides Sub OnInit(ByVal e As EventArgs)
        '
        ' CODEGEN: This call is required by the ASP.NET Web Form Designer.
        '
        InitializeComponent()
        MyBase.OnInit(e)
    End Sub

    '''		Required method for Designer support - do not modify
    '''		the contents of this method with the code editor.
    ''' </summary>
    Private Sub InitializeComponent()
        AddHandler Me.Load, New System.EventHandler(AddressOf Me.Page_Load)

    End Sub
#End Region

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Put user code to initialize the page here
        Dim scriptStr As String = "javascript:return popUpCalendar(this," & getClientID() & ", 'dd/mm/yyyy', '__doPostBack(\'" & getClientID() & "\')')"
        imgCalendar.Attributes.Add("onclick", scriptStr)
    End Sub

End Class
